home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / list10.arc / LIST.C next >
Encoding:
C/C++ Source or Header  |  1987-08-12  |  3.4 KB  |  141 lines

  1. /*
  2.     Program: LIST
  3.         Program to list ASCII text files to the crt or printer.
  4.         Written in Turbo C v1.0, by Ron Zablocki 10 Feb 87.
  5.         Compiled using the TINY memory model; use EXE2BIN to
  6.         convert to LIST.BIN, rename file to LIST.COM.
  7. */
  8.  
  9. #include <stdio.h>
  10.  
  11.  
  12. #define CLEAR        "\033[2J"  /* ANSI.SYS escape code f/screen clear, MS-DOS */
  13. #define PAUSELINE   22        /* Number of lines displayed before pausing.   */
  14. #define LST_OUTPUT "prn"      /* Define standard printer/lst output, MS-DOS  */
  15.  
  16.  
  17.  
  18. /*    display_intro(): displays program introduction.
  19.  *        input: none.
  20.  *        return: void.
  21.  */
  22. void display_intro()
  23. {
  24.     char *msg;
  25.  
  26.     msg =
  27. "       LIST v1.0, placed into the public domain by Ron Zablocki\n"
  28. "                       10 February 1987\n\n\n"
  29. "    Filenames can be entered via the command line: LIST filename,\n"
  30. "    or if no file is entered, you will be prompted for one.  You\n"
  31. "    have the option of listing the ASCII file to the screen or the\n"
  32. "    printer.  If the screen is selected, the display will pause\n"
  33. "    after each screen with the option to quit the listing.  If the\n"
  34. "    printer is selected, make sure the printer is on-line and ready.\n"
  35. "    A form feed will be sent to printer after the file is finished\n"
  36. "    printing.\n\n\n\n";
  37.  
  38.     printf("%s", msg);
  39. }
  40. /* end display_intro() */
  41.  
  42.  
  43.  
  44. /*    get_filename(): gets filename to send to list device.
  45.  *        input: int argc, char *argv[].
  46.  *        return: char *.
  47.  */
  48. char *get_filename (int argc, char *argv[])
  49. {
  50.     char     *fname;
  51.     int    count;
  52.  
  53.     puts(CLEAR);
  54.     if (argc == 2)         /* Filename entered on cmd line. */
  55.         fname = argv[1];
  56.     else {
  57.         display_intro();
  58.         printf("Enter filename: ");
  59.         gets(fname);
  60.     }
  61.     /* Convert filename to upper case. */
  62.     for (count = 0; count <= (strlen(fname) - 1); count++)
  63.         fname[count] = toupper(fname[count]);
  64.  
  65.     return(fname);
  66. }
  67. /* end get_filename() */
  68.  
  69.  
  70.  
  71. /*    get_op_device(): gets output device, screen or printer.
  72.  *        input: char *.
  73.  *        return: int.
  74.  */
  75. int get_op_device (char *filename)
  76. {
  77.     char chr;
  78.  
  79.     puts(CLEAR);
  80.     printf("List %s to Screen or Printer (S/P)? ", filename);
  81.     for (;;) {
  82.         chr = toupper(getch());
  83.         if (chr == 'S' || chr == 'P')
  84.             break;
  85.     }
  86.     return(chr == 'S') ? 1 : 2;     /* 1=Screen, 2=Printer. */
  87. }
  88. /* end get_op_device() */
  89.  
  90.  
  91.  
  92. /*
  93.  *     main().
  94.  */
  95. main (int argc, char *argv[])
  96. {
  97.     int    ch, line, device;
  98.     char    *filename;
  99.     FILE    *f1, *f2;
  100.  
  101.     puts(CLEAR);
  102.     filename = get_filename(argc, argv);
  103.     if ((f1 = fopen(filename, "r")) == NULL) {
  104.         printf("\n\nError: Cannot open file %s\n\n\n", filename);
  105.         exit(1);
  106.     }
  107.     device = get_op_device(filename);  /* Device #: 1=Screen, 2=Printer */
  108.     if (device == 1) {
  109.         puts("Screen\n\n");
  110.         line = 0;
  111.         while ((ch = getc(f1)) != EOF) {
  112.             if (ch == '\n')
  113.                 line++;
  114.             putchar(ch);
  115.             if (line == PAUSELINE) {
  116.                 line = 0;    /* Reset line counter. */
  117.                 printf("\n\t\tPress any key to continue, or Q to Quit...\n");
  118.                 if(toupper(getch()) == 'Q')
  119.                     break;
  120.             }
  121.         }
  122.         exit(0);
  123.     }
  124.     else {                /* List file to printer. */
  125.         puts("Printer");
  126.         if ((f2 = fopen(LST_OUTPUT, "w")) == NULL) {
  127.             printf("\n\n\Error: Printer not ready...");
  128.             exit(1);
  129.         }
  130.         printf("\n\n\n\t\t\tPrinting file: %s", filename);
  131.         while ((ch = getc(f1)) != EOF)
  132.             fputc(ch, f2);
  133.         fprintf(f2, "%c", 12);    /* Send form feed to printer. */
  134.         fclose(f2);
  135.         puts(CLEAR);
  136.         printf("\nFile: %s, finished printing.\n\n\n", filename);
  137.     }
  138.     fclose(f1);
  139. }
  140. /* end main */
  141.